package conference.model;

import java.util.Observable;


/**
*
* An abstract of a conference state. This class is extended and used in separate classes on the client side and server side.
* @author Samsjo-8
*/
public abstract class ConferenceState extends Observable{
	
	//Change-Arguments
	public static enum NOTIFICATION_TYPE {
		CLIENT_LIST_UPDATE, 
		CONFERENCE_PARTICIPATION_UPDATE,
		BROADCASTER_UPDATE, //in ClientState: only used when That client wants to broadcast
		PRIVATE_TALK_UPDATE};  //CALL_STATE_UPDATE, //not used by server: does direct-update

	public static int TCP_PORT = 1235;
	protected Client currentBroadcaster=null;
	protected ClientList list= new ClientList(this);
	
	public ConferenceState(Client currentBroadcaster, boolean hasEnteredConference, ClientList list){
		this.list=list;
		this.currentBroadcaster=currentBroadcaster;
	}
	
	public ConferenceState(){}
	
/**
*
* 
* @return the client list
*/
	public ClientList getList(){
		return list;
	}
	
/**
  *
  * sets the client list
  */
	public void setList(ClientList cl){
		list=cl;
		this.setChanged();
		this.notifyObservers(NOTIFICATION_TYPE.CLIENT_LIST_UPDATE);
	}
	
   /**
  *
  *
  * @return the currently broadcasting client
  */
 
	public Client getCurrentBroadCaster(){
		return currentBroadcaster;
	}
	
	
	/**
  *
  *
  * @return true if the conference currently has a broadcaster, otherwise false
  */
 
	boolean hasCurrentBroadCaster(){
		return currentBroadcaster!=null;
	}
	
   /**
  *
  * call this method to set that the conference state has been changed
  */
 
	protected void setChanged(){
		super.setChanged();
	}
	
	/**
	 * checks if the nickName is in use
	 * @param nickName
	 * @return
	 */
	public boolean nickIsInUse(String nickName){
		return list.getClientFromNickname(nickName)!=null;
	}
	
   /**
  *
  *
  * call this method to set a broadcaster
  */
 
	public void setBroadCaster(Client c){
		this.currentBroadcaster=c;
		this.setChanged();
		this.notifyObservers(NOTIFICATION_TYPE.BROADCASTER_UPDATE);
	}
	
	
}
